﻿using B.S.Domain.Process.ProcessmaintenanceModel;
using B.S.Domain.Process.ProcessrouteName;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.ProcessrouteApplication
{
    public class AddProcessrouteCommandHorter:IRequestHandler<AddProcessrouteCommand,APIRequst<int>>
    {
        IBaseRepository<Processroute> repository;

        public AddProcessrouteCommandHorter(IBaseRepository<Processroute> repository)
        {
            this.repository = repository;
        }

        public async Task<APIRequst<int>> Handle(AddProcessrouteCommand request, CancellationToken cancellationToken)
        {
            var tracebackInfo = new Processroute
            {
                 ProcessrouteName = request.ProcessrouteName,
                Image = request.Image,
                ProcessrouteType = request.ProcessrouteType,
                ProcessrouteState = false,
                ProcessrouteDescription = request.ProcessrouteDescription
            };
            // 保存到数据库
            var result = await repository.Add(tracebackInfo);
            return new APIRequst<int>()
            {

                Data = result,
                Msg = "添加成功"
            };
        }
    }
}
